package cn.farm.farm.Mapper.OridinaryMapper;


import cn.farm.farm.Entity.Ordinary.Information;
import cn.farm.farm.Entity.Ordinary.InformationSon;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

public interface InformationMapper {

    @Insert("insert into information(title,content,author,time,location,images,videos)" +
            " values(#{title},#{content},#{author},#{time},#{location},#{images},#{videos})")
    int insert(Information information);

    @Select("select * from information where author = #{id}")
    List<Information> select(int id);

    @Delete("delete from information where infoID = #{infoID}")
    int delete(int infoID);

    @Update("update information set title=#{title},content=#{content},author=#{author},time=#{time},location=#{location} where infoID = #{infoID}")
    int update(Information information);

    @Insert("insert into image (name,description,author,imageFile,location,time)" +
            "values(#{name},#{description},#{author},#{imagePath},#{location},#{time})")
    void AddImage(String name, String location, int author, String imagePath, String description, String time);

    @Insert("insert into match_image (imageID,matchinfo) value(#{imageID},#{matchinfo})")
    void insertMatch(Integer imageID,String matchinfo);

    @Insert("insert into match_image (matchId,imageID,matchinfo) values(#{matchId},#{imageID},#{matchInfo})")
    void insertMatchImage(Integer matchId, Integer imageID, String matchInfo);

    @Insert("insert into video (name,description,author,videoFile,location,time)" +
            "values(#{name},#{description},#{author},#{videoPath},#{location},#{time})")
    void insertVideo(String name, String location, int author, String videoPath, String description, String time);

    @Insert("insert into information (title,content,author,time,location,images,videos)" +
            "values(#{title},#{content},#{author},#{time},#{location},#{matchId},#{vedioId})")
    void AddInformation(String title, String content, int author, String location, Integer matchId, Integer vedioId, String time);

    @Select("select imageID from image where imageFile = #{imagePath} ")
    Integer foundbyPath(String imagePath);

    @Select("select matchID from match_image where imageID = #{imageID} ")
    Integer foundbyimage(Integer imageID);

    @Select("select videoID from video where videoFile = #{vedioPath} ")
    Integer foundbyvideoPath(String videoPath);

    @Select("select * from information where author = #{author}")
    @Results({
            @Result(column = "images" , property = "images",
                    many=@Many(select = "cn.farm.farm.Mapper.CommonMapper.MatchMapper.getimageID",fetchType= FetchType.EAGER)),
            @Result(column = "videos" , property = "videos",
                    many=@Many(select = "cn.farm.farm.Mapper.OridinaryMapper.VideoMapper.foundVideo",fetchType= FetchType.EAGER))
    })
    List<InformationSon> foundbyAuthor(int author);
}

